package com.qindian;

import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.qindian.coupontest.R;
import com.qindian.model.GoodsModel;

import java.util.Locale;

/**
 * Author: Li
 * Date: 2018/4/28 0028
 * Description:
 */

public class GoodsAdapter extends BaseQuickAdapter<GoodsModel.DataBean.ListBean,BaseViewHolder> {
    private String mType;
    public GoodsAdapter(int layoutResId,String type) {
        super(layoutResId);
        mType=type;
    }

    @Override
    protected void convert(BaseViewHolder helper, GoodsModel.DataBean.ListBean item) {

        helper.setText(R.id.txt_title,item.getTitle());
        Glide.with(mContext).load(item.getItempic()).into((ImageView) helper.getView(R.id.img_coupon));

        //原价
        String originPrice=item.getOrigin_price();
        //券面价
        String couponPrice="";
        double price= Double.parseDouble(item.getOrigin_price())-Double.parseDouble(item.getShop_price());

        switch (mType) {
            case "tb":
                couponPrice=String.format(Locale.CHINA,"%.2f",price);
                break;
            case "jd":
                couponPrice=item.getShop_price();
                break;
        }
        helper.setText(R.id.txt_price,"价格："+originPrice);
        helper.setText(R.id.txt_coupon_price,"可抵扣："+couponPrice);

    }
}
